<#-- 标准表单宏定义 -->
<#macro standardForm formContent newButtons bottomButtons iconCls title extensionPoint1 script submitUrl dialogMode=true checkSession=true showToolbar=true showSaveButton=model.showSaveButton showSaveAndCreateButton=model.showSaveAndCreateButton showSaveAndCloseButton=model.showSaveAndCloseButton enctype="application/x-www-form-urlencoded">
<#include "/common/macro/includeJavascript.ftl" />
<#include "/common/macro/includeStylesheet.ftl" />
	<div class="layui-layout-body">
	<div class="layui-layout layui-layout-admin">
	<#if showToolbar>
		<div id="formHeader_${model.clientId}" class="layui-header">
			<#if title??&&!dialogMode><div class="panel-title"><#if iconCls??>><i class="${iconCls}" aria-hidden="true"></i><#else><i class="icon-编辑" aria-hidden="true"></i></#if> ${title}</div></#if>
			${extensionPoint1}
			<div class="mtdl-toolbar clearfix">
				<div class="layui-btn-group" style="margin : 5px 20px;">
					<#if showSaveButton>
						<button class="layui-btn layui-save layui-save-refresh" style="margin-left:30px;" title="保存">
							<i class="fa fa-check"></i> 保存
						</button>
					</#if>
					<#if showSaveAndCreateButton>
						<button class="layui-btn layui-save layui-save-create" style="margin-left:30px;" title="保存并新建">
							<i class="fa fa-user-plus"></i> 保存并新建
						</button>
					</#if>
					<#if showSaveAndCloseButton>
						<button class="layui-btn layui-save layui-save-close" style="margin-left:30px;" title="保存并关闭">
							<i class="fa fa-user-times"></i> 保存并关闭
						</button>
					</#if>
					<button class="layui-btn layui-refresh" style="margin-left:30px;" title="刷新">
					  <i class="fa fa-refresh"></i> 刷新
					</button>
				</div>
				${newButtons}
				<#--
					<#if model.params.showNavButton[0]=="true">
					<div style="float:right;margin-top: 5px;">
						<a href="#" id="btnPrevious_${model.clientId}" class="plain linkbutton" style="font-size:25px;"><i class="fa fa-angle-left" aria-hidden="true"></i></a>
						<a href="#" id="btnNext_${model.clientId}" class="plain linkbutton" style="font-size:25px;"><i class="fa fa-angle-right" aria-hidden="true"></i></a>
					</div>
					</#if>
				-->
			</div>
		</div>
	</#if>
	<div class="mtdl-form-content layui-body">
		<form id="form_${model.clientId}" method="POST" enctype="${enctype}" class="form-horizontal edit-form" style="height:100%">
			<div class="exception-panel" style="display:none;"></div>
			<input type="hidden" name="id" value="${record.id}"></input>
			<input type="hidden" id="version_${model.clientId}" name="version" value="${record.version}"></input>
			${formContent}
			<#if model.params.parentPropertyPath[0]??>
			<input type="hidden" name="_parentPropertyPath" value="${model.params.parentPropertyPath[0]}"></input>
			</#if>
			<#if model.params.parentId[0]??>
			<input type="hidden" name="_parentId" value="${model.params.parentId[0]}"></input>
			</#if>
			<div style="display:none">
				<input type="text" />
			</div>
		</form>
	</div>
    <#if bottomButtons??>
		<div data-options="region:'south',border:false" style="max-height:400px;overflow:hidden;">
			<div class="datagrid-toolbar toolbar-bottom clearfix">
				<div class="pull-right">
					${bottomButtons}
				</div>
			</div>
		</div>
	</#if>
	</div>
	</div>
<script>
	layui.use(['layer','form'], function(){
		var form = layui.form;
		addBtnRefreshClickListener();
		addBtnSaveClickListener();
		formValInit(form);
	});
	// 表单赋值
	function formValInit(form){
		// form.val("form_${model.clientId}", ${recordJson});
	}
	function addBtnSaveClickListener(){
		$(".layui-save").on("click",function(){
			var $this = $(this);
			// 表单提交
			$('#form_${model.clientId}').ajaxSubmit({
			type: 'post',
			url: '${submitUrl}',
			success: function(data, textStatus, jqXHR) {
				if(data.statusCode == "200"){
					parent.layer.alert(data.message, { icon: 6,shadeClose: true });
					if($this.hasClass("layui-save-refresh")){
						window.location.href = '${url}?recordId='+data.recordId;
					}
					if($this.hasClass("layui-save-create")){
						window.location.href = '${url}';
					}
					if($this.hasClass("layui-save-close")){
						parent.layer.close(parent.layer.getFrameIndex(window.name));
					}
				}else{
					layer.alert(data.message, { icon: 5,shadeClose: true });
				}
			},
			error: function (jqXHR, textStatus, errorThrown){
				layer.alert(errorThrown, { icon: 5,shadeClose: true });
			}
		});
			
		})
	}
	
	function addBtnRefreshClickListener(){
		$(".layui-refresh").on("click",function(){
			window.location.reload();
		})
	}
	<#if script == null>
	// magicsoft.standardForm.initialize(options);
	</#if>
	${script}
	
</script>
</#macro>